﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using Fulcrum.ControlGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.ControlGenerator
{
    [TestClass]
    public class AttachedDependencyPropertyXmlConfigurationTests
    {
        public AttachedDependencyPropertyXmlConfigurationTests()
        {
            // nothing
        }

        const string StandardXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' getSummary='My get summary.' setSummary='My set summary.'></blah>";
        const string EmptyGetSummayrXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' getSummary='' setSummary='My set summary.'></blah>";
        const string MissingGetSummaryXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' setSummary='My set summary.'></blah>";
        const string EmptySetSummayrXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' getSummary='My get summary.' setSummary=''></blah>";
        const string MissingSetSummaryXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' getSummary='My get summary.' ></blah>";

        [TestMethod]
        public void TestReaderAdvancement()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            Assert.IsTrue(xmlReader.IsStartElement());

            var config = new AttachedDependencyPropertyXmlConfiguration(xmlReader);

            Assert.IsFalse(xmlReader.IsStartElement());
        }

        [TestMethod]
        public void TestGetSummary()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new AttachedDependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("My get summary.", config.GetMethodSummary);
        }

        [TestMethod]
        public void TestGetSummaryEmpty()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyGetSummayrXml);
            var config = new AttachedDependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("", config.GetMethodSummary);
        }

        [TestMethod]
        public void TestGetSummaryMissing()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingGetSummaryXml);
            var config = new AttachedDependencyPropertyXmlConfiguration(xmlReader);

            Assert.IsNull(config.GetMethodSummary);
        }

        [TestMethod]
        public void TestSetSummary()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new AttachedDependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("My set summary.", config.SetMethodSummary);
        }

        [TestMethod]
        public void TestSetSummaryEmpty()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptySetSummayrXml);
            var config = new AttachedDependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("", config.SetMethodSummary);
        }

        [TestMethod]
        public void TestSetSummaryMissing()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingSetSummaryXml);
            var config = new AttachedDependencyPropertyXmlConfiguration(xmlReader);

            Assert.IsNull(config.SetMethodSummary);
        }

    }
}
